import express from 'express';
import path from 'path';
import cookieParser from 'cookie-parser';
import logger from 'morgan';
import cors from 'cors';
import { fileURLToPath } from 'url';
import { dirname } from 'path';

// 路由导入使用import
import indexRouter from './routes/index.js';
import usersRouter from './routes/users.js';
import spaceRouter from './routes/space.js';
import messageRouter from './routes/message.js';
import groupRouter from './routes/group.js';
import commentRouter from './routes/comment.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const app = express();

app.use(cors());
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());

app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/comment', commentRouter);
app.use('/group', groupRouter);
app.use('/message', messageRouter);
app.use('/space', spaceRouter);

export default app;
